describe Game do
  before do
    @game = Game.new
  end

  # context(状況を説明)
  context "すべてガターの場合" do
    it "スコアは0点" do
      20.times { roll_gutter }
      @game.score.should == 0
    end
  end

  context "すべて1ピンの場合" do
    it "スコアは20点" do
      20.times { @game.roll(1) }
      @game.score.should == 20
    end
  end

  context "ストライクの場合" do
    it "スコアは24点" do
      roll_strike
      @game.roll(3)
      @game.roll(4)
      18.times { roll_gutter }
      @game.score.should == 24
    end
  end

  context "パーフェクトゲーム場合" do
    it "スコアは300点" do
      12.times { roll_strike }
      @game.score.should == 300
    end
  end

  context Game, "スペアの場合" do
    it "スコアは21点" do
      roll_spare
      @game.roll(4)
      @game.roll(3) # 21
      16.times { roll_gutter }
      @game.score.should == 21
    end
  end

  #[1,4,4,5,6,4,5,5,10,0,1,7,3,6,4,10,2,8,6] => 133
  context "受け入れゲームの場合" do
    it "スコアは133点" do
      [1,4,4,5,6,4,5,5,10,0,1,7,3,6,4,10,2,8,6].each {|pin| @game.roll pin}
      @game.score.should == 133
    end
  end
end

private

def roll_gutter
  @game.roll(0)
end

def roll_strike
  @game.roll(10)
end

def roll_spare
  @game.roll(5)
  @game.roll(5)
end